/******************************init****************************/
function saveWorkguide() {
	var url = create_url('workguide-save');
	var parm = $('#editCategoryForm').serialize();
	$.ajax({type:'POST', url:url, data:parm,
	 	success:function(result) {
			if (result == 'success') {
				sys_msg('操作成功!');
				sys_load_handle('workguide');
			} else {
				sys_msg('操作失败!!');
			}
		}
	});
}

function selectCategory() {
	var url = create_url('workguide-aidInit');
	var parm = {'id':'pc', 'name':'pn'};
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'400px', height:'600px', open:true});
}

function clearForm() {
	$(':input','#editCategoryForm')  
	 .not(':button, :submit, :reset')  
	 .val('')  
	 .removeAttr('checked')  
	 .removeAttr('selected');
	 
	 $('#pc').val('0');
	 $('#pn').val('0');
}
function checkedWorkguide(){
	var name = $("#name").val();
	if(name.length == 0){
		sys_msg('请输入类型名称');
		return
	}
	saveWorkguide();
}
/************edit******************/
function addFilesUploadEvent_workguide() {
	var url = create_url('workguide-uploads');
	var btn = $('#uploadFilesBtn');
	new AjaxUpload(btn, {
		action:url,
		name:'files',
		multiple: true,
		responseType: 'json',
		onSubmit : function(file, ext) {
			if (ext && /^(zip|rar|txt|doc|docx|xls|xlsx|ppt|pptx|pdf|ZIP|RAR|TXT|DOC|DOCX|XLS|XLSX|PPT|PPTX|PDF)$/.test(ext)){
				this.setData({
					'info':'文件类型正确'
				});
			} else {
				sys_msg('文件类型错误', '只能上传类型为：zip、rar、txt、doc、docx、xls、xlsx、ppt、pptx、pdf');
				return false;               
			}
			$('#upload_span').html(sys_loading_img);
			this.disable();
		},
		onComplete: function(files, response){
			if ('error' == response.result)
				sys_msg('失败', '上传文件失败，请检查文件名是否正确!');
			else if ('file_type_error' == response.result)
				sys_msg('文件类型错误', '只能上传类型为：JGP、GIF、BMP、ICO、PNG的文件!');
			else {
				var template = $('#tempAnnexListDiv').find('.rep');
				var annexList = $('#annexListTable');
				var index = parseInt($('#workguidedetail_an_index').val());
				$.each(response.list, function(i) {
					var pii = template.clone(true);
					pii.find('.title').html(response.list[i].name + "." +response.list[i].ext).end()
						.find('.name').attr('name', 'List[' + (index + i) + '].name').val(response.list[i].name).end()
						.find('.size').attr('name', 'List[' + (index + i) + '].size').val(response.list[i].size).end()
						.find('.sn').attr('name', 'List[' + (index + i) + '].sn').val(response.list[i].path).end()
						.find('.ext').attr('name', 'List[' + (index + i) + '].ext').val(response.list[i].ext).end()
						.find('.afcs').val(response.list[i].code).end();
					annexList.append(pii);
					index ++;
				});
				this.enable();
				$('#workguidedetail_an_index').val(index);
			}
		}
	});
}
function deleteSelectedItem(btn) {
	btn.parents('.rep').remove();
}
